const app = getApp()

Page({
  data: {
    websiteUrl: ''
  },

  onLoad: function (options) {
    console.log('网站跳转页面加载')
    
    const url = options.url || app.globalData.websiteUrl
    this.setData({
      websiteUrl: url
    })
  },

  onShow: function () {
    console.log('网站跳转页面显示')
  },

  openInBrowser: function() {
    const url = this.data.websiteUrl
    
    wx.showModal({
      title: '打开外部链接',
      content: `即将跳转到：${url}`,
      confirmText: '打开',
      cancelText: '取消',
      success: (res) => {
        if (res.confirm) {
          // 复制到剪贴板
          wx.setClipboardData({
            data: url,
            success: () => {
              wx.showToast({
                title: '链接已复制，请在浏览器中打开',
                icon: 'none',
                duration: 3000
              })
            }
          })
        }
      }
    })
  },

  copyUrl: function() {
    wx.setClipboardData({
      data: this.data.websiteUrl,
      success: () => {
        wx.showToast({
          title: '网址已复制',
          icon: 'success'
        })
      },
      fail: () => {
        wx.showToast({
          title: '复制失败',
          icon: 'none'
        })
      }
    })
  },

  shareWebsite: function() {
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
    
    wx.showToast({
      title: '点击右上角分享',
      icon: 'none'
    })
  },

  onShareAppMessage: function (res) {
    return {
      title: 'AGI助手 - 智能AI工具平台',
      path: '/pages/webview/webview',
      imageUrl: '/images/share.png'
    }
  },

  onShareTimeline: function (res) {
    return {
      title: 'AGI助手 - 智能AI工具平台'
    }
  }
})